/**
 * 
 */
package org.homeunix.thecave.plugins;

import javax.swing.JPanel;

/**
 * Implements the Import Options dialog layout
 * 
 * @author santthosh
 *
 */
/**
 * @author rkanne
 *
 */
/**
 * @author rkanne
 *
 */
public class ImportPanel extends JPanel {
		
	   
    /** Creates new form ImportPanel */
    public ImportPanel() {
        initComponents();
        
        profileChooser = new javax.swing.JFileChooser();
        saveChooser = new javax.swing.JFileChooser();
        
        importOptionButtonGroup.add(standardImport);        
        importOptionButtonGroup.add(manualImport);       
        
        standardImport.setSelected(true);    
        settingsPanel.setEnabled(false);   
        disableManualSettings();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
    private void initComponents() {
        importOptionButtonGroup = new javax.swing.ButtonGroup();
        accountButtonGroup = new javax.swing.ButtonGroup();
        optionsPanel = new javax.swing.JPanel();
        instruction = new javax.swing.JLabel();
        standardImport = new javax.swing.JRadioButton();
        manualImport = new javax.swing.JRadioButton();
        settingsPanel = new javax.swing.JPanel();
        settingsInstruction = new javax.swing.JLabel();
        headersPresent = new javax.swing.JCheckBox();
        dateFormatSelect = new javax.swing.JComboBox();
        dateFormatLabel = new javax.swing.JLabel();
        fieldLocationInstruction = new javax.swing.JLabel();
        dateLabel = new javax.swing.JLabel();
        dateSelect = new javax.swing.JComboBox();
        numberLabel = new javax.swing.JLabel();
        numberSelect = new javax.swing.JComboBox();
        descriptionLabel = new javax.swing.JLabel();
        amountLabel = new javax.swing.JLabel();
        fromLabel = new javax.swing.JLabel();
        toLabel = new javax.swing.JLabel();
        memoLabel = new javax.swing.JLabel();
        descriptionSelect = new javax.swing.JComboBox();
        amountSelect = new javax.swing.JComboBox();
        fromSelect = new javax.swing.JComboBox();
        toSelect = new javax.swing.JComboBox();
        memoSelect = new javax.swing.JComboBox();
        importButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        optionsPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        instruction.setFont(new java.awt.Font("Dialog", 0, 12));
        instruction.setText("Please choose one of the import types");

        standardImport.setFont(new java.awt.Font("Dialog", 0, 12));
        standardImport.setText("This file was earlier exported using CSV Export plugin.");
        standardImport.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        standardImport.setMargin(new java.awt.Insets(0, 0, 0, 0));
        standardImport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                standardImportActionPerformed(evt);
            }
        });

        manualImport.setFont(new java.awt.Font("Dialog", 0, 12));
        manualImport.setText("Let me choose the fields");
        manualImport.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        manualImport.setMargin(new java.awt.Insets(0, 0, 0, 0));
        manualImport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                manualImportActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout optionsPanelLayout = new javax.swing.GroupLayout(optionsPanel);
        optionsPanel.setLayout(optionsPanelLayout);
        optionsPanelLayout.setHorizontalGroup(
            optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(instruction)
                    .addComponent(standardImport)
                    .addComponent(manualImport))
                .addContainerGap(215, Short.MAX_VALUE))
        );
        optionsPanelLayout.setVerticalGroup(
            optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(instruction)
                .addGap(15, 15, 15)
                .addComponent(standardImport)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(manualImport)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        settingsPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        settingsInstruction.setFont(new java.awt.Font("Dialog", 0, 12));
        settingsInstruction.setText("Please select the options for the manual import");

        headersPresent.setFont(new java.awt.Font("Dialog", 0, 12));
        headersPresent.setSelected(true);
        headersPresent.setText("Ignore headers");
        headersPresent.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        headersPresent.setMargin(new java.awt.Insets(0, 0, 0, 0));

        dateFormatSelect.setEditable(true);
        dateFormatSelect.setFont(new java.awt.Font("Dialog", 0, 12));
        dateFormatSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MM/dd/yyyy" }));
        dateFormatSelect.setMinimumSize(new java.awt.Dimension(68, 19));
        dateFormatSelect.setPreferredSize(new java.awt.Dimension(68, 19));

        dateFormatLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        dateFormatLabel.setText("Date Format:");

        fieldLocationInstruction.setFont(new java.awt.Font("Dialog", 0, 12));
        fieldLocationInstruction.setText("Please specify the field locations in the CSV file [0 is the first field]");

        dateLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        dateLabel.setText("1. Date : ");

        dateSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" }));
        dateSelect.setMinimumSize(new java.awt.Dimension(118, 19));
        dateSelect.setPreferredSize(new java.awt.Dimension(118, 19));

        numberLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        numberLabel.setText("2. Number:");

        numberSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" }));
        numberSelect.setMinimumSize(new java.awt.Dimension(118, 19));
        numberSelect.setPreferredSize(new java.awt.Dimension(118, 19));

        descriptionLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        descriptionLabel.setText("3. Description:");

        amountLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        amountLabel.setText("4. Amount:");

        fromLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        fromLabel.setText("5. From: ");

        toLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        toLabel.setText("6. To:");

        memoLabel.setFont(new java.awt.Font("Dialog", 0, 12));
        memoLabel.setText("7. Memo:");

        descriptionSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" }));
        descriptionSelect.setMinimumSize(new java.awt.Dimension(118, 19));
        descriptionSelect.setPreferredSize(new java.awt.Dimension(118, 19));

        amountSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" }));
        amountSelect.setMinimumSize(new java.awt.Dimension(118, 19));
        amountSelect.setPreferredSize(new java.awt.Dimension(118, 19));

        fromSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" }));
        fromSelect.setMinimumSize(new java.awt.Dimension(118, 19));
        fromSelect.setPreferredSize(new java.awt.Dimension(118, 19));

        toSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" }));
        toSelect.setMinimumSize(new java.awt.Dimension(118, 19));
        toSelect.setPreferredSize(new java.awt.Dimension(118, 19));

        memoSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" }));
        memoSelect.setMinimumSize(new java.awt.Dimension(118, 19));
        memoSelect.setPreferredSize(new java.awt.Dimension(118, 19));

        javax.swing.GroupLayout settingsPanelLayout = new javax.swing.GroupLayout(settingsPanel);
        settingsPanel.setLayout(settingsPanelLayout);
        settingsPanelLayout.setHorizontalGroup(
            settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(settingsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(settingsInstruction, javax.swing.GroupLayout.PREFERRED_SIZE, 339, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(descriptionLabel)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, settingsPanelLayout.createSequentialGroup()
                        .addComponent(headersPresent)
                        .addGap(193, 193, 193)
                        .addComponent(dateFormatLabel)
                        .addGap(12, 12, 12))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, settingsPanelLayout.createSequentialGroup()
                        .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(dateLabel)
                            .addComponent(numberLabel)
                            .addComponent(fromLabel)
                            .addComponent(memoLabel)
                            .addComponent(toLabel)
                            .addComponent(amountLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                        .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(numberSelect, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(dateSelect, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(descriptionSelect, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(amountSelect, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(fromSelect, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(toSelect, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(memoSelect, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(211, 211, 211))
                    .addComponent(fieldLocationInstruction, javax.swing.GroupLayout.PREFERRED_SIZE, 382, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dateFormatSelect, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        settingsPanelLayout.setVerticalGroup(
            settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(settingsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(settingsInstruction)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(headersPresent)
                    .addComponent(dateFormatLabel)
                    .addComponent(dateFormatSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(15, 15, 15)
                .addComponent(fieldLocationInstruction)
                .addGap(25, 25, 25)
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dateLabel)
                    .addComponent(dateSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(numberLabel)
                    .addComponent(numberSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(descriptionLabel)
                    .addComponent(descriptionSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(amountSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(amountLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fromSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fromLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(toSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(toLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(memoSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(memoLabel))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        importButton.setFont(new java.awt.Font("Dialog", 0, 12));
        importButton.setMnemonic('i');
        importButton.setText("Import");

        cancelButton.setFont(new java.awt.Font("Dialog", 0, 12));
        cancelButton.setMnemonic('c');
        cancelButton.setText("Cancel");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(208, 208, 208)
                        .addComponent(importButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelButton))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(optionsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(settingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(optionsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addComponent(settingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(importButton)
                    .addComponent(cancelButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>                        

    /**
     * Enables the field selection panel if importing non-native file
     * 
     * @param evt
     */
    private void manualImportActionPerformed(java.awt.event.ActionEvent evt) {                                             
            settingsPanel.setEnabled(true);
            enableManualSettings();
    }                                            

    /**
     * Event handler for disabling the field selection panel 
     * if importing from exported file.
     * 
     * @param evt
     */
    private void standardImportActionPerformed(java.awt.event.ActionEvent evt) {                                               
            settingsPanel.setEnabled(false);
            disableManualSettings();
    }     
    
    /**
     * Disables the controls for manually ordering fields 
     */
    private void disableManualSettings()
    {
        headersPresent.setEnabled(false);
        dateFormatSelect.setEnabled(false);
        dateSelect.setEnabled(false);
        numberSelect.setEnabled(false);
        descriptionSelect.setEnabled(false);
        amountSelect.setEnabled(false);
        fromSelect.setEnabled(false);
        toSelect.setEnabled(false);
        memoSelect.setEnabled(false);        
    }
    
    /**
     * Enables the controls for manually ordering fields
     */
    private void enableManualSettings()
    {
        headersPresent.setEnabled(true);
        dateFormatSelect.setEnabled(true);
        dateSelect.setEnabled(true);
        numberSelect.setEnabled(true);
        descriptionSelect.setEnabled(true);
        amountSelect.setEnabled(true);
        fromSelect.setEnabled(true);
        toSelect.setEnabled(true);
        memoSelect.setEnabled(true);        
    }
    
   
    // Variables declaration - do not modify                     
    public javax.swing.ButtonGroup accountButtonGroup;
    public javax.swing.JLabel amountLabel;
    public javax.swing.JComboBox amountSelect;
    public javax.swing.JButton cancelButton;
    public javax.swing.JLabel dateFormatLabel;
    public javax.swing.JComboBox dateFormatSelect;
    public javax.swing.JLabel dateLabel;
    public javax.swing.JComboBox dateSelect;
    public javax.swing.JLabel descriptionLabel;
    public javax.swing.JComboBox descriptionSelect;
    public javax.swing.JLabel fieldLocationInstruction;
    public javax.swing.JLabel fromLabel;
    public javax.swing.JComboBox fromSelect;
    public javax.swing.JCheckBox headersPresent;
    public javax.swing.JButton importButton;
    public javax.swing.ButtonGroup importOptionButtonGroup;
    public javax.swing.JLabel instruction;
    public javax.swing.JRadioButton manualImport;
    public javax.swing.JLabel memoLabel;
    public javax.swing.JComboBox memoSelect;
    public javax.swing.JLabel numberLabel;
    public javax.swing.JComboBox numberSelect;
    public javax.swing.JPanel optionsPanel;
    public javax.swing.JLabel settingsInstruction;
    public javax.swing.JPanel settingsPanel;
    public javax.swing.JRadioButton standardImport;
    public javax.swing.JLabel toLabel;
    public javax.swing.JComboBox toSelect;
    // End of variables declaration                   
    public javax.swing.JFileChooser profileChooser;
    public javax.swing.JFileChooser saveChooser;
}
